<?php

    /*
     *
     *  This file is part of ValerieEngine
     *  ValerieEngine is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  ValerieEngine is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with ValerieEngine.  If not, see <http://www.gnu.org/licenses/>.
     *
     */

    /**
     * @desc Класс регистра для хранения глобальных переменных
     *
     * @author Dutchak Vitaly
     */
    final class Register extends ArrayObject {

        private $_data = array();

        /**
         *
         * @desc Конструктор класса.
         *
         * @param array $array
         *
         */
        public function __construct($array=array()) {

            if (is_array($array))
                $this->_data = $array;
            
            VEngine::Error("Test Error");
        }

        /**
         *
         * (non-PHPdoc)
         * @see ArrayObject::offsetSet()
         */
        public function offsetSet($offset, $value) {

            $this->data[$offset] = $value;
        }

        /**
         * (non-PHPdoc)
         * @see ArrayObject::offsetExists()
         */
        public function offsetExists($offset) {

            return isset($this->data[$offset]);
        }

        /**
         * (non-PHPdoc)
         * @see ArrayObject::offsetUnset()
         */
        public function offsetUnset($offset) {

            unset($this->data[$offset]);
        }

        /**
         * (non-PHPdoc)
         * @see ArrayObject::offsetGet()
         */
        public function offsetGet($offset) {

            return isset($this->data[$offset]) ? $this->data[$offset] : null;
        }

        /**
         *
         * @desc Реализация волшебного метода __get для текущего класса
         *
         * @param string $name
         * @return mixed
         */
        public function __get($name) {

            return $this->_data[$name];
        }

        /**
         *
         * @desc Реализация волшебного метода __set для текущего класса
         * @param string $name
         * @param mixed $value
         *
         */
        public function __set($name, $value) {

            if (!isset($this->_data[$name]))
                $this->_data[$name] = $value;
            else
                new Error ("Ошибка записи в Реестр, ключ [{$name}] уже существует!");
        }

        /**
         * (non-PHPdoc)
         * @see ArrayObject::append()
         */
        public function append($value) {

            $this->_data[] = $value;
        }

        /**
         *
         * @desc Dump data
         *
         */
        public function dump() {

            var_dump($this->_data);
        }

    }

    /**
     *
     * @desc Класс реализующий доступ к объекту как к ассоциативному массиву
     * @author Dutchak Vitaly
     *
     */
?>
